/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import dao.AnswerDao;
import dao.PersonDao;
import dao.QuestionDao;
import dao.SubjectDao;
import dao.TestDao;
import entities.Answer;
import entities.Person;
import entities.Question;
import entities.Subject;
import entities.Test;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author Oksana_Moroz
 */
public class Main {

    public static void main(String[] args) {
        ApplicationContext appx = new ClassPathXmlApplicationContext("base-context.xml");
        
        PersonDao pd = appx.getBean("personDaoImpl", dao.PersonDaoImpl.class);        
        Person p = pd.findByLoginPassword("liviniya", "12345678");
        System.out.println(p.getSurname() + " " + p.getName());   
        
        SubjectDao sd = appx.getBean("subjectDaoImpl", dao.SubjectDaoImpl.class);        
        Subject s = sd.findById(11);
        System.out.println(s.getName());
        
        TestDao td = appx.getBean("testDaoImpl", dao.TestDaoImpl.class);      
        List<Test> tests = td.findByTutorId(13);
        for (Test t : tests) {
            System.out.println("Questions: " + t.getQuests() + ", variants: " + t.getVariants());
        }
        
        QuestionDao qd = appx.getBean("questionDaoImpl", dao.QuestionDaoImpl.class);        
        Question q = qd.findById(36);
        System.out.println(q.getText());
        
        AnswerDao ad = appx.getBean("answerDaoImpl", dao.AnswerDaoImpl.class);      
        List<Answer> answers = ad.findByQuestionId(36);
        for (Answer a : answers) {
            System.out.println(a.getLetter() + ") " + a.getText());
        }
    }
}
